package cn.tedu.ivos.dictoption.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.dictoption.pojo.dto.DictOptionQuery;
import cn.tedu.ivos.dictoption.pojo.dto.DictOptionSaveParam;
import cn.tedu.ivos.dictoption.pojo.vo.DictOptionVO;
import cn.tedu.ivos.dictoption.service.DictOptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/dictOption")
public class DictOptionController {
    @Autowired
    DictOptionService dictOptionService;
    @GetMapping("select")
    public JsonResult selectDictO(DictOptionQuery dictOptionQuery){
        log.debug("查询字典选项业务：{}",dictOptionQuery);
        List<DictOptionVO> list=dictOptionService.selectDictO(dictOptionQuery);
        return JsonResult.ok(list);
    }
    @PostMapping("save")
    public JsonResult saveDictO(DictOptionSaveParam dictOptionSaveParam){
        log.debug("保存字典选项业务：{}",dictOptionSaveParam);
        dictOptionService.saveDictO(dictOptionSaveParam);
        return JsonResult.ok();
    }
    @PostMapping("delete/{id}")
    public JsonResult deleteDictO(@PathVariable Long id){
        log.debug("删除字典选项业务：{}",id);
        dictOptionService.deleteDictO(id);
        return JsonResult.ok();
    }
    /* 定义一个根据字典code查字典项的方法 */
    @GetMapping("select/{code}")
    public JsonResult selectDictOByCode(@PathVariable String code){
        log.debug("根据字典code查询字典项业务：{}",code);
        List<DictOptionVO> list=dictOptionService.selectDictOByCode(code);
        log.debug("查询------------结果：{}",list);
        return JsonResult.ok(list);
    }
}
